package com.tuniu.agents.impl.train;

import com.tuniu.agents.agent.AgentManagerGroup;
import com.tuniu.agents.common.agent.Recommender;
import com.tuniu.agents.common.handler.TrainStreamResponseHandler;
import com.tuniu.agents.common.service.itinerary.ItineraryService;
import com.tuniu.agents.impl.train.enums.TrainAgentEnum;
import com.tuniu.agents.impl.train.logger.TrainAgentLoggingService;
import com.tuniu.agents.message.MessageLogger;
import com.tuniu.agents.message.MessageSender;
import com.tuniu.agents.tools.train.tool.SearchAllTrainTool;
import com.tuniu.agents.tools.train.tool.SearchConditionTrainTool;
import com.tuniu.agents.tools.train.tool.SearchTrainDetailTool;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
 * train ticket Agent Bean config
 */
@Configuration
public class TrainAgentConfig {

    public static final String AGENT_ID = "TrainTicketAgent";
    public static final String TRAIN_PARSE_LIST_AGENT_ID = "TRAIN_PARSE_LIST";
    public static final String TRAIN_PARSE_DETAIL_AGENT_ID = "TRAIN_PARSE_DETAIL";

    @Autowired
    private ItineraryService itineraryService;

    @Bean(AGENT_ID)
    @SneakyThrows
    public TrainTicketAgent trainTicketAgent(AgentManagerGroup agentManagerGroup,MessageSender messageSender) {
        Map<String, String> toolAnalysisMap = Map.of(
                SearchAllTrainTool.TOOLNAME, TRAIN_PARSE_LIST_AGENT_ID,
                SearchConditionTrainTool.TOOLNAME, TRAIN_PARSE_LIST_AGENT_ID
        );

        MessageLogger logger = new MessageLogger(TrainAgentLoggingService.BEAN_NAME);
        return new TrainTicketAgent(agentManagerGroup, TrainAgentConfig.AGENT_ID, messageSender,TrainAgentEnum.TRAIN_TICKET_AGENT.getPromptTemplateId(),logger,toolAnalysisMap,
                SearchAllTrainTool.TOOLNAME,SearchConditionTrainTool.TOOLNAME,  SearchTrainDetailTool.TOOLNAME);
    }

    @Bean(TRAIN_PARSE_LIST_AGENT_ID)
    @SneakyThrows
    public Recommender trainParseListAgent(AgentManagerGroup agentManagerGroup){
        return new TrainRecommender(agentManagerGroup, TRAIN_PARSE_LIST_AGENT_ID,TrainAgentEnum.TRAIN_PARSE_LIST_AGENT.getPromptTemplateId(),new TrainStreamResponseHandler(SearchAllTrainTool.TOOLNAME,TRAIN_PARSE_LIST_AGENT_ID,agentManagerGroup.getChatEnvironmentMemory(),agentManagerGroup.getMemoryManager(),agentManagerGroup.getMessageRender(),itineraryService));
    }

}
